package com.boot.dog.web.config;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.boot.dog.web.config.handler.DataAuthInterceptor;
import com.boot.dog.web.config.handler.MetaHandler;
import lombok.AllArgsConstructor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @Author: MaxLv
 * @Date: 2019/12/2
 */
@Configuration
@MapperScan(value = "com.boot.dog.mapper")
@AllArgsConstructor
public class MybatisPlusConfig {

    @Resource
    DataSource dataSource;

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    @Bean
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setMetaObjectHandler(new MetaHandler());
        return globalConfig;
    }

    @Bean
    public DataAuthInterceptor dataAuthInterceptor() {
        return new DataAuthInterceptor(dataSource);
    }

}
